﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 设计模式
{
    class company_do
    {
        public static void main()
        {
            concrete_company root = new concrete_company("北京总公司");
            root.add(new hr_department("总公司人力资源"));
            root.add(new finance_department("总公司财务部"));

            concrete_company comp = new concrete_company("上海华东分公司");
            comp.add(new hr_department("华东分公司人力资源"));
            comp.add(new finance_department("华东分公司财务部"));
            root.add(comp);

            concrete_company comp1 = new concrete_company("南京办事处");
            comp1.add(new hr_department("南京办事处人力资源"));
            comp1.add(new finance_department("南京办事处财务部"));
            comp.add(comp1);

            Console.WriteLine("\n结构图：");
            root.display(1);

            Console.WriteLine("\n职责：");
            root.duty();

            Console.Read();
        }


    }

    abstract class company
    {
        public string name;
        public company(string name)
        {
            this.name = name;
        }

        public abstract void add(company c);
        public abstract void remove(company c);
        public abstract void display(int depth);
        public abstract void duty();
    }

    class concrete_company : company
    {
        List<company> children = new List<company>();
        public concrete_company(string name) : base(name) { }

        public override void add(company c)
        {
            children.Add(c);
        }

        public override void remove(company c)
        {
            children.Remove(c);
        }

        public override void display(int depth)
        {
            Console.WriteLine(new string('-', depth) + name);

            foreach (company component in children)
            {
                component.display(depth + 2);
            }
        }

        public override void duty()
        {
            foreach (company component in children)
            {
                component.duty();
            }
        }

    }

    class hr_department : company
    {
        public hr_department(string name) : base(name) { }

        public override void add(company c)
        {

        }

        public override void remove(company c)
        {

        }

        public override void display(int depth)
        {
            Console.WriteLine(new string('-', depth)+ name);
        }

        public override void duty()
        {
            Console.WriteLine("{0} 员工招聘培训管理", name);
        }

    }

    class finance_department : company
    {
        public finance_department(string name) : base(name) { }

        public override void add(company c)
        {

        }

        public override void remove(company c)
        {

        }

        public override void display(int depth)
        {
            Console.WriteLine(new string('-', depth)+ name);
        }

        public override void duty()
        {
            Console.WriteLine("{0} 公司财务收支管理", name);
        }




    }


}
